package api.cie.rss;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import api.cie.rss.adapters.FileListAdapter;

/**
 * The class to display the list of files containing favorite articles
 * @author STL
 *
 */
public class FavoriteListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.file_list);
		fillData();
		initialize();
	}

	private void initialize() {
		ImageButton btnDelete = (ImageButton)findViewById(R.id.btnDeleteFile);
		btnDelete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				List<String> selectedFiles = ((FileListAdapter)FavoriteListActivity.this.getListAdapter()).getSelectedFiles();
				if(selectedFiles == null) return;
				for(String name:selectedFiles) {
					FavoriteListActivity.this.deleteFile(name);
				}
				fillData();
			}
		});
	}

	private void fillData() {
		List<String> files = new ArrayList<String>();
		for(String str:fileList()) {
			files.add(str);
		}
		FileListAdapter fileAdapter = new FileListAdapter(this);
		fileAdapter.setFiles(files);
		
		setListAdapter(fileAdapter);
	}
	
	
	
}
